
var app = getApp();
Page({
  data:{
    userInfo: {},
    title: '四级趣闻',
    author: '学英语的西坝',
    time: '2天前',
    look: 300,
    like: 20,
    isLikeBtn: true,
    defaultText: '',
    imgUrls: [
        '/Imag/轮播1.jpg',
        '/Imag/轮播2.jpg',
        '/Imag/轮播3.jpg',
        '/Imag/轮播4.jpg',
    ],
    
    comments: [
        {
            imgurl: '/Imag/lyk.jpg',
            name: '旧事酒浓',
            time: '38分钟前',
            comment: '童话般的感觉~点个赞~！'
        },
        {
            imgurl: '/Imag/kjq.jpg',
            name: '康大帅哥',
            time: '2小时前',
            comment: '色彩好温馨'
        },
        {
            imgurl: '/Imag/71e01ad3cee4bb5d798babc3b653be5.jpg',
            name: '杜紫藤',
            time: '3小时前',
            comment: '嚯~可以啊'
        }
    ]
  },
//   onLoad:function(options){
//     var _this = this;
//     app.getUserInfo(function(userInfo){
//       //更新数据
//       _this.setData({
//         userInfo:userInfo
//       });
//     })
//   },
  onReady:function(){
    // 页面渲染完成
  },
  onShow:function(){
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
//   likeEvent: function(e) {
//     wx.showToast({
//         title: '推荐成功',
//         icon: 'success'
//     });
//     this.setData({
//         like: this.data.like + 1,
//         isLikeBtn: false
//     });
//   },
  // 提交评论
  formSubmit: function(e) {
    var _this = this;
    var comment = e.detail.value.comment;
    console.log(e);
    wx.showToast({
        title: '发表中',
        icon: 'loading'
    });
    _this.setData({
        defaultText: comment
    });
    if (comment && comment !== '') {
        setTimeout(function(res) {
           console.log(res);
            wx.hideToast();
            var nickname = _this.data.userInfo.nickName;
            var imgurl = _this.data.userInfo.avatarUrl;
            var time = '刚刚发表';
            var comments = _this.data.comments;
            
            comments.unshift({
                imgurl: imgurl,
                name: nickname,
                time: time,
                comment: comment
            });
            e.detail.value.comment = '';
            _this.setData({
                comments: comments,
                defaultText: ''
            });
            wx.showToast({
                title: '发表成功',
                icon: 'success'
            });
        }, 500);
    } else {
        wx.hideToast();
        wx.showModal({
            title: '提示',
            content: '评论内容不能为空。',
            showCancel: false,
            confirmText: '我知道了'
        })
    }
  },
})